﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using Cosmetic.DataAccess;
using Cosmetic.DataEntity;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Cosmetic.Logic
{
    public class articleclassManger:LogicBase
    {
        public void Insert(articleclass aProduct)
        {
            m_CosmeticDC.articleclass .InsertOnSubmit(aProduct);
            m_CosmeticDC.SubmitChanges();
        }
        /* 购物指南类别添加 */
        public void Inserts( helpclass helpclass)
        {
            m_CosmeticDC.helpclass.InsertOnSubmit(helpclass );
            m_CosmeticDC.SubmitChanges();
        }

        public void Deltes( helpclass helpclass)
        {
            m_CosmeticDC.helpclass.DeleteOnSubmit( helpclass );
            m_CosmeticDC.SubmitChanges();
        }

        public List<helpclass > getallhelpclass()
        {
            return (from theActivity in m_CosmeticDC.helpclass 
                    select theActivity).ToList();
        }

        public helpclass  GetProductByIdclass(int? aProductId)
        {
            return m_CosmeticDC.helpclass .Single(theProect => theProect.id == aProductId);
        }



        public static DataTable GetProductInfoByIds0(int aProductId)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);

            try
            {
                con.Open();
                string cmdStr = string.Empty;
                cmdStr = "select classname from helpclass where id='" + aProductId + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                SqlDataAdapter adap = new SqlDataAdapter(com);
                DataSet ds = new DataSet();
                adap.Fill(ds);
                return ds.Tables[0];
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// Delete product
        /// </summary>
        /// <param name="aProduct">The product want delete</param>
        public void Delete(articleclass aProduct)
        {

            m_CosmeticDC.articleclass .DeleteOnSubmit(aProduct);
            m_CosmeticDC.SubmitChanges();
        }

        public List<articleclass > GetAll()
        {
            return (from theActivity in m_CosmeticDC.articleclass 
                    select theActivity).ToList();
        }

     public articleclass   GetProductById(int  aProductId)
        {
            return m_CosmeticDC.articleclass  .Single(theProect => theProect.id   == aProductId);
        }



     public static DataTable GetProductInfoByIds(int aProductId)
     {
         string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
         SqlConnection con = new SqlConnection(conStr);

         try
         {
             con.Open();
             string cmdStr = string.Empty;
             cmdStr = "select name from articleclass where id='" + aProductId + "'";
             SqlCommand com = new SqlCommand(cmdStr, con);
             SqlDataAdapter adap = new SqlDataAdapter(com);
             DataSet ds = new DataSet();
             adap.Fill(ds);
             return ds.Tables[0];
         }
         finally
         {
             con.Close();
         }
     }



    }
}
